<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/Admin/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <% IEnumerable<User> users = ((IEnumerable<User>)ViewData["NewestRegistrations"]).OrderByDescending(x => x.RegisterDate).Take(5); %>
    <% IEnumerable<ReportedPost> ReportedPosts = ((IEnumerable<ReportedPost>)ViewData["ReportedPosts"]).OrderByDescending(x => x.Date).Take(5); %>
    <h2>AdminCP</h2>
   
    <fieldset>
        <legend>Recent User Registration</legend>

        <table class="form_table">    
            <tr>
                <th>Username</th>
                <th>Email</th>
                <th>Status</th>
                <th>Last Login</th>
            </tr>
            
            <% int i = 0;
               foreach(User u in users){ %>
                <tr class="<%= i++ % 2 == 0 ? "" : "bg_color3" %>">
                    <td><%= Html.ActionLink(u.Username, "UserDetails", "Users", new { UserID = u.UserID }, null) %></td>
                    <td><%= u.Email %></td>
                    <td><%= string.IsNullOrEmpty(u.ActivationCode) ? "<span class='active'>Active</span>" : "<span class='inactive'>Inactive</span>" %></td>
                    <td><%= Html.RelativeDate(u.LastLoginDate) %> from <%= u.LastLoginIP %></td>
                </tr>
            <%} %>
        </table>
                
        <p>
            &#187; <%= Html.ActionLink("View All Users", "Users", "Users")  %>
        </p>

    </fieldset>    


    <fieldset>
        <legend>Reported Posts</legend>
        <table class="form_table">
            <tr>
                <th>Post Text</th>
                <th>Date</th>
                <th></th>
                <th></th>
            </tr>
            
            <% if (ReportedPosts.Count() == 0){ %>
            <tr>
                <td colspan="4" style="text-align: center">No reported posts</td>
            </tr>
            <% } %>
            
            <% int q = 0;
               foreach(ReportedPost rp in ReportedPosts){ %>
            <tr class="<%= q++ % 2 == 0 ? "" : "bg_color3" %>">
                <td><%= rp.Post.Text.Shorten(25) %></td>
                <td><%= Html.RelativeDate(rp.Date) %></td>
                <td><%= Html.ActionLink("Mark as Safe", "MarkAsSafe", new { ReportedPostID = rp.PostID }, null) %></td>
                <td><%= Html.AdminConfirm("Delete", Url.Action("DeletePost", "Post", new { PostID = rp.PostID }), Url.Action("Index")) %></td>
            </tr>
            <% } %>
        </table>
        
        <p>
            &#187; <%= Html.ActionLink("View All Reported Posts (" + ReportedPosts.Count() + ")", "ReportedPosts")%>
        </p>

    </fieldset>    

</asp:Content>
